package generatorModel

import (
	"CommonsProject/models/commonsModel"
	"CommonsProject/pkg/tools/sqlTool"
	"fmt"
	"strings"
)

// Column  生成表中的字段
type Column struct {
	commonsModel.Model
	FieldName     string `from:"fieldName" json:"fieldName" gorm:"column:field_name;size:100;comment:字段名称"`
	FieldJsonName string `from:"fieldJsonName" json:"fieldJsonName" gorm:"column:field_json_name;size:100;comment:Json字段名称"`
	FieldFormName string `from:"fieldFormName" json:"fieldFormName" gorm:"column:field_form_name;size:100;comment:Form字段名称"`
	FieldSQLName  string `from:"fieldSQLName" json:"fieldSQLName" gorm:"column:field_sql_name;size:100;comment:SQL字段名称"`
	FieldSQLType  string `from:"fieldSQLType" json:"fieldSQLType" gorm:"column:field_sql_type;size:100;comment:SQL字段类型"`
	FieldType     string `from:"fieldType" json:"fieldType" gorm:"column:field_type;size:100;comment:字段类型"`
	FieldSize     uint   `from:"fieldSize" json:"fieldSize" gorm:"column:field_size;size:10;comment:Json字段类型大小"`
	FieldComment  string `from:"fieldComment" json:"fieldComment" gorm:"column:field_comment;size:10;comment:Json字段类型备注"`
	IsEdit        bool   `from:"isEdit" json:"isEdit" gorm:"column:is_edit;size:100;comment:是否可编辑"`
	IsShow        bool   `from:"isShow" json:"isShow" gorm:"column:is_show;size:100;comment:是否列表"`
	IsSearch      bool   `from:"isSearch" json:"isSearch" gorm:"column:is_search;size:100;comment:是否搜索"`
	Component     string `from:"component" json:"component" gorm:"column:component;size:100;comment:输入控件(1普通文本、2文本域、3数字、4下拉框)"`
	TableID       uint   `json:"tableID" gorm:"column:table_id;comment:外键"`
}

func (c Column) TableName() string {
	return "generator_column"
}

// ToLower 转为小写
func (c *Column) ToLower() {
	c.FieldJsonName = fmt.Sprint(strings.ToLower(fmt.Sprintf("%c", c.FieldName[0])), c.FieldName[1:])
	c.FieldFormName = fmt.Sprint(strings.ToLower(fmt.Sprintf("%c", c.FieldName[0])), c.FieldName[1:])
	c.FieldSQLName = sqlTool.ToLowerField(c.FieldName)
}
